package com.example.jpa_demo.repository;

import com.example.jpa_demo.entity.Student;
import org.springframework.data.jpa.repository.JpaRepository;
import org.springframework.data.jpa.repository.Query;
import org.springframework.data.repository.query.Param;
import org.springframework.stereotype.Repository;

import java.util.List;

/**
 * @Description
 * @Author lihw
 * @Date 2023/12/11 10:15
 */
@Repository
public interface StudentRepository extends JpaRepository<Student, Long> {

    /**
     * 原生sql
     * @param stuId
     * @return
     */
    @Query(value = "SELECT * FROM student WHERE stu_id = :stuId", nativeQuery = true )
    List<Student> getStuListById(@Param("stuId") Long stuId);

    /**
     *  jpa的 JPQL
     * @param stuId
     * @return
     */
    @Query(value = "select new Student(stuId, name, age, classId) from Student where stuId = :stuId")
    Student getStudentById2(@Param("stuId") Long stuId);


}
